// pages/paySuccess/paySuccess.js
const app = getApp();
let Api = require('../../api/api.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        userHeadPortrait:'',
        sendType:'',
        orderType:'',
        ordernumber:'',
        listData:[],
        shareuserid:'',
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        let self = this;
        self.setData({
            sendType: options.sendType,
            orderType: options.orderType,
            ordernumber: options.ordernumber,
            userHeadPortrait: app.globalData.userInfo.avatarUrl, //用户头像
        })
        //18）我的订单列表
        Api.get(app.globalData.mallDomain, {
            doShowMyOrderList: 1,
            status: 1, //  测试status为2 运行是status值1，
            token: app.globalData.token,
            ordernumber: options.ordernumber,
        }).then(res => {
            console.log(res,'支付订单列表内容')
            let list = [];
            res.data.list[0].list.forEach(ele => {
                list.push({
                    wpName: unescape(ele.wpName),
                    wpViceName: ele.wpViceName,
                    customvalue: ele.customvalue,
                    wpCover: ele.wpCover,
                    wsPrice: parseInt(ele.wsPrice),
                    wsPrice_1: ele.wsPrice.substring(ele.wsPrice.length - 2, ele.wsPrice.length),
                })
            })
            self.setData({
                listData:list
            })
        })
        //15）根据Token获取用户Id、用于转赠
        Api.get(app.globalData.mallDomain, {
            doGetUserIdToToken: 1,
            token: app.globalData.token,
        }).then(res => {
            console.log(res, '根据Token获取用户Id、用于转赠')
            if(res.data.msg == '114'){
                self.setData({
                    shareuserid: res.data.userid,
                })
            }
        })
    },
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {
        let self = this;
        //status=2 测试暂时用待付款的数据代替  实际用  1
        // orderType  自定义订单 ， 普通订单 两种类型
        return {
            title: self.data.listData[0].wpName,
            path: 'pages/forwarding/forwarding?shareuserid=' + self.data.shareuserid + '&status=1&ordernumber=' + self.data.ordernumber + '&orderType=' + self.data.orderType,
            imageUrl: self.data.listData[0].wpCover,
            success: function (res) {
                wx.showToast({
                    title: '分享成功',
                    icon: 'success',
                    duration: 2000
                })
            },
            fail: function (res) {
                console.log("转发失败:" + JSON.stringify(res));
            }
        }
    },
    /**
     * 跳转到查看订单页面
     */
    viewOrder: function() {
        wx.navigateTo({
            url: '../myOrder/myOrder?tabsType=待发货'
        })
    },
    /**
     * 跳转到首页
     */
    toIndex: function () {
        wx.navigateTo({
            url: '../index/index'
        })
    },
    
    
})